home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8657 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What is referencing good for?
  5. Date: 25 Feb 1996 22:04:19 GMT
  6. Organization: self-employed
  7. Message-ID: <4gqmd3$ci3@news.bridge.net>
  8. References: <4goojd$a9g@wintermute.ecs.fullerton.edu> <4goutn$31u@news.bridge.net> <3130c026.8571250@news2.cts.com>
  9. NNTP-Posting-Host: ppp-mia1-43.bridge.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15.  
  16. >>>>>
  17. int& operator[] ( int index )
  18. >    {
  19. >        return dataBlock [ index ] ;
  20. >    }
  21. >    // constructor etc etc
  22. >} ;
  23. >
  24. >
  25. >
  26. >    array  ar ;
  27. >    ar[4] = 0 ;      // can't be done with pointers
  28. >
  29. >
  30. <<<<<
  31.  
  32.  
  33. >Good example, but.... the next question begs to be answered.  Why
  34. >would anybody want to do this?  It essentially gives public access to
  35. >datablock, which is a private variable.
  36.  
  37.  
  38.    Oh no, it does not. There is no way to modify dataBlock. You can find 
  39. out what value is in it by taking the address
  40.  
  41.                   & ar[0]
  42.  
  43. but that does not even prove that dataBlock exists - I could eliminate 
  44. dataBlock, store that address in a completely different format, and then 
  45. rewrite the operator function to work in exactly the same way as seen 
  46. from outside.
  47.  
  48.                                    David
  49.  
  50.  
  51.